/*
 * 产品属性列表
 * @Author: ljb
 * @Date: 2018-03-27 17:53:05
 * @Last Modified by: kanglin
 * @Last Modified time: 2018-06-07 16:55:50
 */
<style lang="less" rel="stylesheet/less" type="text/less" scoped>

</style>
<template>
	<div class="v-admin-product-attribute-index">

		<Table :columns="columns" 
:loading="loading" border :data="attributes" @on-sort-change="sortable"/>

	</div>
</template>

<script>

import Button from 'iview/src/components/button';
import Icon from 'iview/src/components/icon';

export default {
	name: 'ProductAttributeIndex',
	props: ['loading', 'attributes'],
	data() {
		return {
			columns: [
				// {
				//     type: 'selection',
				//     width: 60,
				//     align: 'center'
				// },
				{
					title: 'id',
					key: 'id',
					align: 'center',
					render: (h, { row }) => <div> { row.id || '-' } </div>,
				},
				{
					title: '属性名称',
					key: 'name',
					align: 'center',
					render: (h, { row }) => <div> { row.name || '-' } </div>,
				},
				{
					title: '属性值',
					key: 'values',
					align: 'center',
					render: (h, { row }) => <div> { row.values.length > 0 ? row.values.join(',') : '-' } </div>,
				},
				{
					title: '所属模型',
					key: 'product_mod',
					align: 'center',
					render: (h, { row }) => <div> { row.product_mod ? row.product_mod.name : '-' } </div>,
				},
				{
					title: '创建时间',
					key: 'created_at',
					align: 'center',
					sortable: 'custom',
					render: (h, { row }) => <div> { !row.created_at ? '-' : row.created_at } </div>,
				},
				{
					title: '操作',
					align: 'center',
					render: (h, { row }) =>
						<div>
							<Button size="small" style={{ marginRight: '5px' }} on-click={() => { this.$emit('edit', row); }} type="primary">
								{ this.$t('common.edit') }
							</Button>
						</div>

					// <Button size="small" on-click={() => {this.$emit('delete',row.id)}} type="error">删除属性</Button>
					,
				},
			],
		};
	},
	methods: {

		/**
         * 排序的回调
         * @param  {Object} param {对应列的属性对象,里面包含了column列属性，key值，order排序字段}
         * @return {undefined}
         */
		sortable(param) {
			const search_param = {

				order_by: param.key,

				sort: param.order === 'normal' ? '' : param.order,

			};

			this.$emit('sort', search_param);
		},

	},
};
</script>
